<?php
 jimport('joomla.application.component.view');
 // Load the view framework
 if(!class_exists('VmView'))require(JPATH_COMPONENT_ADMINISTRATOR.DS.'helpers'.DS.'vmview.php');
 jimport('joomla.html.pane');
class svViewLoaisunghiep extends JView
{
	function display()
	{
		$task = JRequest::getCMD('task');
		switch ($task)
		{
			case 'add':
				$this->_edit();
				break;
			case 'edit':
				$this->_edit();
				break;
			default :
				$this->_default();
				break;
		}
		parent::display();
	}
	// hien thi chi tiet
	function _default()
	{
		jimport('joomla.html.pagination');
		$model=$this->getModel('loaisunghiep');
		// phan trang
		$total=$model->getTotal();
		$view=JRequest::getVar('view');
		global $mainframe;
		$param['limitstart']=$mainframe->getUserStateFromRequest('com_svquanlycanbo.'.$view.'.limitstart', 'limitstart',0,'int');
		$param['limit']=$mainframe->getUserStateFromRequest('com_svquanlycanbo.'.$view.'.limit', 'limit',$mainframe->getCfg('list_limit'),'int');
		$pager=new JPagination($total, $param['limitstart'], $param['limit']);
		// sap xep
		$param['order']=$mainframe->getUserStateFromRequest('com_svquanlycanbo.'.$view.'.order', 'filter_order','lsn_id','cmd');
		$param['order_Dir']=$mainframe->getUserStateFromRequest('com_svquanlycanbo.'.$view.'.orderDir', 'filter_order_Dir','DESC','word');
		// fill du lieu
		$objectList=$model->getAllLoaisunghiep($param);
		$this->assignRef('pager', $pager);
		$this->assignRef('param', $param);
		$this->assignRef('objectList', $objectList);
		//$this->_gridToolbar();
		//toolbar
		$this->toolbarDefault('Quản lý các loại sự nghiệp ');
	}
	function _edit()
	{
		$idlist    = JRequest::getVar('cid',array(0),'','array');
		JArrayHelper::toInteger($idlist, array(0));
		$id     = $idlist[0];
		if($id==0)
		{
			$this->toolbarAdd('Thêm mới loại sự nghiệp');
		}
		else
		{
			$this->toolbarEdit('Chỉnh sửa một loại sự nghiệp');
		}
		// lay du lieu tu model
		$model=$this->getModel('loaisunghiep');
		$object=$model->getLoaisunghiepByID($id);
		// set layout
		$this->assignRef('id', $id);
		$this->assignRef('object', $object);
		$this->setLayout('edit');
	}
	// them cac button tren thanh toolbar
	function toolbarDefault($title)
	{
		JToolBarHelper::title($title);
		JToolBarHelper::addNew();
		JToolBarHelper::editListX();
		JToolBarHelper::deleteList();
	}
	function toolbarAdd($title)
	{
		JRequest::setVar( 'hidemainmenu', 1 );
		JToolBarHelper::title($title);
		JToolBarHelper::save();
		JToolBarHelper::cancel();
	}
	function toolbarEdit($title)
	{
		JRequest::setVar( 'hidemainmenu', 1 );
		JToolBarHelper::title($title);
		JToolBarHelper::save();
		JToolBarHelper::apply();
		JToolBarHelper::cancel();
	}
	
}
?>